home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / exec / findtask.c < prev    next >
C/C++ Source or Header  |  1996-10-24  |  2KB  |  107 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: findtask.c,v 1.5 1996/10/24 15:50:49 aros Exp $
  4.     $Log: findtask.c,v $
  5.     Revision 1.5  1996/10/24 15:50:49  aros
  6.     Use the official AROS macros over the __AROS versions.
  7.  
  8.     Revision 1.4  1996/08/13 13:56:02  digulla
  9.     Replaced AROS_LA by AROS_LHA
  10.     Replaced some AROS_LH*I by AROS_LH*
  11.     Sorted and added includes
  12.  
  13.     Revision 1.3  1996/08/01 17:41:11  digulla
  14.     Added standard header for all files
  15.  
  16.     Desc:
  17.     Lang:
  18. */
  19. #include <exec/execbase.h>
  20. #include <aros/libcall.h>
  21.  
  22. /*****************************************************************************
  23.  
  24.     NAME */
  25.     #include <clib/exec_protos.h>
  26.  
  27. AROS_LH1(struct Task *, FindTask,
  28.  
  29. /*  SYNOPSIS */
  30.     AROS_LHA(STRPTR, name, A1),
  31.  
  32. /*  LOCATION */
  33.     struct ExecBase *, SysBase, 49, Exec)
  34.  
  35. /*  FUNCTION
  36.     Find a task with a given name or get the address of the current task.
  37.     Finding the address of the current task is a very quick function
  38.     call, but finding a special task is a very CPU intensive instruction.
  39.     Note that generally a task may already be gone when this function
  40.     returns.
  41.  
  42.     INPUTS
  43.     name - Pointer to name or NULL for current task.
  44.  
  45.     RESULT
  46.     Address of task structure found.
  47.  
  48.     NOTES
  49.  
  50.     EXAMPLE
  51.  
  52.     BUGS
  53.  
  54.     SEE ALSO
  55.  
  56.     INTERNALS
  57.  
  58.     HISTORY
  59.  
  60. ******************************************************************************/
  61. {
  62.     AROS_LIBFUNC_INIT
  63.  
  64.     struct Task *ret;
  65.  
  66.     /* Quick return for a quick argument */
  67.     if(name==NULL)
  68.     return SysBase->ThisTask;
  69.  
  70.     /* Always protect task lists with a Disable(). */
  71.     Disable();
  72.  
  73.     /* First look into the ready list. */
  74.     ret=(struct Task *)FindName(&SysBase->TaskReady,name);
  75.     if(ret==NULL)
  76.     {
  77.     /* Then into the waiting list. */
  78.     ret=(struct Task *)FindName(&SysBase->TaskWait,name);
  79.     if(ret==NULL)
  80.     {
  81.         /*
  82.         Finally test the current task. Note that generally
  83.         you know the name of your own task - so it is close
  84.         to nonsense to look for it this way.
  85.         */
  86.         char *s1=SysBase->ThisTask->tc_Node.ln_Name;
  87.         char *s2=name;
  88.  
  89.         /* Check as long as the names are identical. */
  90.         while(*s1++==*s2)
  91.         /* Terminator found? */
  92.         if(!*s2++)
  93.         {
  94.             /* Got it. */
  95.             ret=SysBase->ThisTask;
  96.             break;
  97.         }
  98.     }
  99.     }
  100.  
  101.     /* Return whatever I found. */
  102.     Enable();
  103.     return ret;
  104.     AROS_LIBFUNC_EXIT
  105. } /* FindTask */
  106.  
  107.